[FLINK-39583][table-planner] Normalize Calcite correl variables for more effective sub-plan digest reuse#27959
Open
ferenc-csaky wants to merge 1 commit into
Open
Conversation
Collaborator
7ec8e24 to
eb95a68
Compare
eb95a68 to
b803d47
Compare
b803d47 to
88c17e2
Compare
mateczagany
reviewed
May 3, 2026
| } | ||
|
|
||
| @Override | ||
| public RexNode visitSubQuery(RexSubQuery subQuery) { |
Contributor
There was a problem hiding this comment.
I believe this should also be covered by the tests. Right now they don't test sub-queries for correl variable normalization.
Contributor
Author
There was a problem hiding this comment.
I added unit tests to cover this. An integration test e.g. in SubplanReuseTest won't hit this code, because where this normalize is applied in the optimization chain subqueries are actually already rewritten/decorrelated, so it won't make a difference what happens in the normalizer.
The reason it's still useful to have this cause from the scope of the class itself this is how it should behave if it gets a RelNode without context about what kind of optimizations that node went through already.
…ore effective sub-plan digest reuse
88c17e2 to
005e62f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the purpose of the change
Improve digest-based subplan reuse (when
table.optimizer.reuse-optimize-block-with-digest-enabledis set totrue) for plans containing correlation variables, such asCROSS JOIN UNNESTand decorrelated subqueries.Structurally equivalent subplans will receive different Calcite
CorrelationIds during separate view expansions, cause Calcite has global counter to name correlation variables ($cor2, etc). These ids become part of the relational digest, so otherwise identical subplans do not match and cannot be considered for reuse.The change introduces correlation-variable normalization before digest-based reuse, assigning deterministic sequential correlation ids per subplan so equivalent correlated plans produce matching digests.
Brief change log
CorrelVariableNormalizerShuttleto adjust deterministic sequential correl idsSubplanReuseShuttleinRelNodeBlockSubplanReuseTestthat covers the added logicVerifying this change
Added
SubplanReuseTest#testSubplanReuseOnTemporalJoinWithUnnestwhich produces a proper reused exec plan in case the block digest optimization is enabled.Before correl normalization, the exec plan would look like:
Does this pull request potentially affect one of the following parts:
@Public(Evolving): noDocumentation